<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>xhrio.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_net_xhrio.js.html">xhrio.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2006 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Wrapper class for handling XmlHttpRequests.
<a name="line17"></a> *
<a name="line18"></a> * One off requests can be sent through goog.net.XhrIo.send() or an
<a name="line19"></a> * instance can be created to send multiple requests.  Each request uses it&#39;s
<a name="line20"></a> * own XmlHttpRequest object and handles clearing of the event callback to
<a name="line21"></a> * ensure no leaks.
<a name="line22"></a> *
<a name="line23"></a> * XhrIo is event based, it dispatches events for when a request has finished,
<a name="line24"></a> * when it is errorred or has succeeded, or when the ready-state changes.
<a name="line25"></a> * The Ready-state event fires first first, followed by a generic completed
<a name="line26"></a> * event, and lastly the error or success event is fired as appropriate.
<a name="line27"></a> *
<a name="line28"></a> * The error event may also be called before completed and
<a name="line29"></a> * ready-state-change if the XmlHttpRequest.open() or .send() methods throw.
<a name="line30"></a> *
<a name="line31"></a> * This class does not support multiple requests, queuing, or prioritization.
<a name="line32"></a> *
<a name="line33"></a> * Tested = IE6, FF1.5, Safari, Opera 8.5
<a name="line34"></a> *
<a name="line35"></a> * TODO: Error cases aren&#39;t playing nicely in Safari.
<a name="line36"></a> *
<a name="line37"></a> */
<a name="line38"></a>
<a name="line39"></a>
<a name="line40"></a>goog.provide(&#39;goog.net.XhrIo&#39;);
<a name="line41"></a>
<a name="line42"></a>goog.require(&#39;goog.Timer&#39;);
<a name="line43"></a>goog.require(&#39;goog.debug.Logger&#39;);
<a name="line44"></a>goog.require(&#39;goog.debug.errorHandlerWeakDep&#39;);
<a name="line45"></a>goog.require(&#39;goog.events.EventTarget&#39;);
<a name="line46"></a>goog.require(&#39;goog.json&#39;);
<a name="line47"></a>goog.require(&#39;goog.net.ErrorCode&#39;);
<a name="line48"></a>goog.require(&#39;goog.net.EventType&#39;);
<a name="line49"></a>goog.require(&#39;goog.net.XmlHttp&#39;);
<a name="line50"></a>goog.require(&#39;goog.net.xhrMonitor&#39;);
<a name="line51"></a>goog.require(&#39;goog.structs&#39;);
<a name="line52"></a>goog.require(&#39;goog.structs.Map&#39;);
<a name="line53"></a>
<a name="line54"></a>
<a name="line55"></a>/**
<a name="line56"></a> * Basic class for handling XMLHttpRequests.
<a name="line57"></a> * @constructor
<a name="line58"></a> * @extends {goog.events.EventTarget}
<a name="line59"></a> */
<a name="line60"></a>goog.net.XhrIo = function() {
<a name="line61"></a>  goog.events.EventTarget.call(this);
<a name="line62"></a>
<a name="line63"></a>  /**
<a name="line64"></a>   * Map of default headers to add to every request, use:
<a name="line65"></a>   * XhrIo.headers.set(name, value)
<a name="line66"></a>   * @type {goog.structs.Map}
<a name="line67"></a>   */
<a name="line68"></a>  this.headers = new goog.structs.Map();
<a name="line69"></a>};
<a name="line70"></a>goog.inherits(goog.net.XhrIo, goog.events.EventTarget);
<a name="line71"></a>
<a name="line72"></a>/**
<a name="line73"></a> * A reference to the XhrIo logger
<a name="line74"></a> * @type {goog.debug.Logger}
<a name="line75"></a> * @private
<a name="line76"></a> */
<a name="line77"></a>goog.net.XhrIo.prototype.logger_ =
<a name="line78"></a>    goog.debug.Logger.getLogger(&#39;goog.net.XhrIo&#39;);
<a name="line79"></a>
<a name="line80"></a>
<a name="line81"></a>/**
<a name="line82"></a> * The Content-Type HTTP header name
<a name="line83"></a> * @type {string}
<a name="line84"></a> */
<a name="line85"></a>goog.net.XhrIo.CONTENT_TYPE_HEADER = &#39;Content-Type&#39;;
<a name="line86"></a>
<a name="line87"></a>
<a name="line88"></a>/**
<a name="line89"></a> * The Content-Type HTTP header value for a url-encoded form
<a name="line90"></a> * @type {string}
<a name="line91"></a> */
<a name="line92"></a>goog.net.XhrIo.FORM_CONTENT_TYPE =
<a name="line93"></a>    &#39;application/x-www-form-urlencoded;charset=utf-8&#39;;
<a name="line94"></a>
<a name="line95"></a>
<a name="line96"></a>/**
<a name="line97"></a> * All non-disposed instances of goog.net.XhrIo created
<a name="line98"></a> * by {@link goog.net.XhrIo.send} are in this Array.
<a name="line99"></a> * @see goog.net.XhrIo.cleanupAllPendingStaticSends
<a name="line100"></a> * @type {Array.&lt;goog.net.XhrIo&gt;}
<a name="line101"></a> * @private
<a name="line102"></a> */
<a name="line103"></a>goog.net.XhrIo.sendInstances_ = [];
<a name="line104"></a>
<a name="line105"></a>
<a name="line106"></a>/**
<a name="line107"></a> * Static send that creates a short lived instance of XhrIo to send the
<a name="line108"></a> * request.
<a name="line109"></a> * @see goog.net.XhrIo.cleanupAllPendingStaticSends
<a name="line110"></a> * @param {string|goog.Uri} url Uri to make request too.
<a name="line111"></a> * @param {Function} opt_callback Callback function for when request is
<a name="line112"></a> *     complete.
<a name="line113"></a> * @param {string} opt_method Send method, default: GET.
<a name="line114"></a> * @param {string|GearsBlob} opt_content Post data. This can be a Gears blob
<a name="line115"></a> *     if the underlying HTTP request object is a Gears HTTP request.
<a name="line116"></a> * @param {Object|goog.structs.Map} opt_headers Map of headers to add to the
<a name="line117"></a> *     request.
<a name="line118"></a> * @param {number} opt_timeoutInterval Number of milliseconds after which an
<a name="line119"></a> *     incomplete request will be aborted; 0 means no timeout is set.
<a name="line120"></a> */
<a name="line121"></a>goog.net.XhrIo.send = function(url, opt_callback, opt_method, opt_content,
<a name="line122"></a>                               opt_headers, opt_timeoutInterval) {
<a name="line123"></a>  var x = new goog.net.XhrIo();
<a name="line124"></a>  goog.net.XhrIo.sendInstances_.push(x);
<a name="line125"></a>  if (opt_callback) {
<a name="line126"></a>    goog.events.listen(x, goog.net.EventType.COMPLETE, opt_callback);
<a name="line127"></a>  }
<a name="line128"></a>  goog.events.listen(x,
<a name="line129"></a>                     goog.net.EventType.READY,
<a name="line130"></a>                     goog.partial(goog.net.XhrIo.cleanupSend_, x));
<a name="line131"></a>  if (opt_timeoutInterval) {
<a name="line132"></a>    x.setTimeoutInterval(opt_timeoutInterval);
<a name="line133"></a>  }
<a name="line134"></a>  x.send(url, opt_method, opt_content, opt_headers);
<a name="line135"></a>};
<a name="line136"></a>
<a name="line137"></a>
<a name="line138"></a>/**
<a name="line139"></a> * Disposes all non-disposed instances of goog.net.XhrIo created by
<a name="line140"></a> * {@link goog.net.XhrIo.send}.
<a name="line141"></a> * {@link goog.net.XhrIo.send} cleans up the goog.net.XhrIo instance
<a name="line142"></a> * it creates when the request completes or fails.  However, if
<a name="line143"></a> * the request never completes, then the goog.net.XhrIo is not disposed.
<a name="line144"></a> * This can occur if the window is unloaded before the request completes.
<a name="line145"></a> * We could have {@link goog.net.XhrIo.send} return the goog.net.XhrIo
<a name="line146"></a> * it creates and make the client of {@link goog.net.XhrIo.send} be
<a name="line147"></a> * responsible for disposing it in this case.  However, this makes things
<a name="line148"></a> * significanly more complicated for the client, and the whole point
<a name="line149"></a> * of {@link goog.net.XhrIo.send} is that its simple and easy to use.
<a name="line150"></a> * Clients of {@link goog.net.XhrIo.send} should call
<a name="line151"></a> * {@link goog.net.XhrIo.cleanupAllPendingStaticSends} when doing final
<a name="line152"></a> * cleanup on window unload.
<a name="line153"></a> */
<a name="line154"></a>goog.net.XhrIo.cleanup = function() {
<a name="line155"></a>  var instances = goog.net.XhrIo.sendInstances_;
<a name="line156"></a>  while (instances.length) {
<a name="line157"></a>     instances.pop().dispose();
<a name="line158"></a>  }
<a name="line159"></a>};
<a name="line160"></a>
<a name="line161"></a>
<a name="line162"></a>/**
<a name="line163"></a> * Installs exception protection for all entry point introduced by
<a name="line164"></a> * goog.net.XhrIo instances which are not protected by
<a name="line165"></a> * {@link goog.debug.ErrorHandler#protectWindowSetTimeout},
<a name="line166"></a> * {@link goog.debug.ErrorHandler#protectWindowSetInterval}, or
<a name="line167"></a> * {@link goog.events.protectBrowserEventEntryPoint}.
<a name="line168"></a> *
<a name="line169"></a> * @param {goog.debug.ErrorHandler} errorHandler Error handler with which to
<a name="line170"></a> *     protect the entry point(s).
<a name="line171"></a> * @param {boolean} opt_tracers Whether to install tracers around the entry
<a name="line172"></a> *     point.
<a name="line173"></a> */
<a name="line174"></a>goog.net.XhrIo.protectEntryPoints = function(
<a name="line175"></a>    errorHandler, opt_tracers) {
<a name="line176"></a>  goog.net.XhrIo.prototype.onReadyStateChangeEntryPoint_ =
<a name="line177"></a>      errorHandler.protectEntryPoint(
<a name="line178"></a>          goog.net.XhrIo.prototype.onReadyStateChangeEntryPoint_,
<a name="line179"></a>          opt_tracers);
<a name="line180"></a>};
<a name="line181"></a>
<a name="line182"></a>
<a name="line183"></a>/**
<a name="line184"></a> * Disposes of the specified goog.net.XhrIo created by
<a name="line185"></a> * {@link goog.net.XhrIo.send} and removes it from
<a name="line186"></a> * {@link goog.net.XhrIo.pendingStaticSendInstances_}.
<a name="line187"></a> * @param {goog.net.XhrIo} XhrIo An XhrIo created by
<a name="line188"></a> *     {@link goog.net.XhrIo.send}.
<a name="line189"></a> * @private
<a name="line190"></a> */
<a name="line191"></a>goog.net.XhrIo.cleanupSend_ = function(XhrIo) {
<a name="line192"></a>  XhrIo.dispose();
<a name="line193"></a>  goog.array.remove(goog.net.XhrIo.sendInstances_, XhrIo);
<a name="line194"></a>};
<a name="line195"></a>
<a name="line196"></a>
<a name="line197"></a>/**
<a name="line198"></a> * Whether XMLHttpRequest is active.  A request is active from the time send()
<a name="line199"></a> * is called until onReadyStateChange() is complete, or error() or abort()
<a name="line200"></a> * is called.
<a name="line201"></a> * @type {boolean}
<a name="line202"></a> * @private
<a name="line203"></a> */
<a name="line204"></a>goog.net.XhrIo.prototype.active_ = false;
<a name="line205"></a>
<a name="line206"></a>
<a name="line207"></a>/**
<a name="line208"></a> * Reference to an XMLHttpRequest object that is being used for the transfer.
<a name="line209"></a> * @type {XMLHttpRequest|GearsHttpRequest}
<a name="line210"></a> * @private
<a name="line211"></a> */
<a name="line212"></a>goog.net.XhrIo.prototype.xhr_ = null;
<a name="line213"></a>
<a name="line214"></a>
<a name="line215"></a>/**
<a name="line216"></a> * The options to use with the current XMLHttpRequest object.
<a name="line217"></a> * @type {Object?}
<a name="line218"></a> * @private
<a name="line219"></a> */
<a name="line220"></a>goog.net.XhrIo.prototype.xhrOptions_ = null;
<a name="line221"></a>
<a name="line222"></a>
<a name="line223"></a>/**
<a name="line224"></a> * Last URL that was requested.
<a name="line225"></a> * @type {string|goog.Uri}
<a name="line226"></a> * @private
<a name="line227"></a> */
<a name="line228"></a>goog.net.XhrIo.prototype.lastUri_ = &#39;&#39;;
<a name="line229"></a>
<a name="line230"></a>
<a name="line231"></a>/**
<a name="line232"></a> * Method for the last request.
<a name="line233"></a> * @type {string}
<a name="line234"></a> * @private
<a name="line235"></a> */
<a name="line236"></a>goog.net.XhrIo.prototype.lastMethod_ = &#39;&#39;;
<a name="line237"></a>
<a name="line238"></a>
<a name="line239"></a>/**
<a name="line240"></a> * Last error code.
<a name="line241"></a> * @type {goog.net.ErrorCode}
<a name="line242"></a> * @private
<a name="line243"></a> */
<a name="line244"></a>goog.net.XhrIo.prototype.lastErrorCode_ = goog.net.ErrorCode.NO_ERROR;
<a name="line245"></a>
<a name="line246"></a>
<a name="line247"></a>/**
<a name="line248"></a> * Last error message.
<a name="line249"></a> * @type {Error|string}
<a name="line250"></a> * @private
<a name="line251"></a> */
<a name="line252"></a>goog.net.XhrIo.prototype.lastError_ = &#39;&#39;;
<a name="line253"></a>
<a name="line254"></a>
<a name="line255"></a>/**
<a name="line256"></a> * This is used to ensure that we don&#39;t dispatch an multiple ERROR events. This
<a name="line257"></a> * can happen in IE when it does a synchronous load and one error is handled in
<a name="line258"></a> * the ready statte change and one is handled due to send() throwing an
<a name="line259"></a> * exception.
<a name="line260"></a> * @type {boolean}
<a name="line261"></a> * @private
<a name="line262"></a> */
<a name="line263"></a>goog.net.XhrIo.prototype.errorDispatched_ = false;
<a name="line264"></a>
<a name="line265"></a>
<a name="line266"></a>/**
<a name="line267"></a> * Used to make sure we don&#39;t fire the complete event from inside a send call.
<a name="line268"></a> * @type {boolean}
<a name="line269"></a> * @private
<a name="line270"></a> */
<a name="line271"></a>goog.net.XhrIo.prototype.inSend_ = false;
<a name="line272"></a>
<a name="line273"></a>
<a name="line274"></a>/**
<a name="line275"></a> * Used in determining if a call to {@link #onReadyStateChange_} is from within
<a name="line276"></a> * a call to this.xhr_.open.
<a name="line277"></a> * @type {boolean}
<a name="line278"></a> * @private
<a name="line279"></a> */
<a name="line280"></a>goog.net.XhrIo.prototype.inOpen_ = false;
<a name="line281"></a>
<a name="line282"></a>
<a name="line283"></a>/**
<a name="line284"></a> * Used in determining if a call to {@link #onReadyStateChange_} is from within
<a name="line285"></a> * a call to this.xhr_.abort.
<a name="line286"></a> * @type {boolean}
<a name="line287"></a> * @private
<a name="line288"></a> */
<a name="line289"></a>goog.net.XhrIo.prototype.inAbort_ = false;
<a name="line290"></a>
<a name="line291"></a>
<a name="line292"></a>/**
<a name="line293"></a> * Number of milliseconds after which an incomplete request will be aborted and
<a name="line294"></a> * a {@link goog.net.EventType.TIMEOUT} event raised; 0 means no timeout is set.
<a name="line295"></a> * @type {number}
<a name="line296"></a> * @private
<a name="line297"></a> */
<a name="line298"></a>goog.net.XhrIo.prototype.timeoutInterval_ = 0;
<a name="line299"></a>
<a name="line300"></a>
<a name="line301"></a>/**
<a name="line302"></a> * Window timeout ID used to cancel the timeout event handler if the request
<a name="line303"></a> * completes successfully.
<a name="line304"></a> * @type {Object?}
<a name="line305"></a> * @private
<a name="line306"></a> */
<a name="line307"></a>goog.net.XhrIo.prototype.timeoutId_ = null;
<a name="line308"></a>
<a name="line309"></a>
<a name="line310"></a>/**
<a name="line311"></a> * Returns the number of milliseconds after which an incomplete request will be
<a name="line312"></a> * aborted, or 0 if no timeout is set.
<a name="line313"></a> * @return {number} Timeout interval in milliseconds.
<a name="line314"></a> */
<a name="line315"></a>goog.net.XhrIo.prototype.getTimeoutInterval = function() {
<a name="line316"></a>  return this.timeoutInterval_;
<a name="line317"></a>};
<a name="line318"></a>
<a name="line319"></a>
<a name="line320"></a>/**
<a name="line321"></a> * Sets the number of milliseconds after which an incomplete request will be
<a name="line322"></a> * aborted and a {@link goog.net.EventType.TIMEOUT} event raised; 0 means no
<a name="line323"></a> * timeout is set.
<a name="line324"></a> * @param {number} ms Timeout interval in milliseconds; 0 means none.
<a name="line325"></a> */
<a name="line326"></a>goog.net.XhrIo.prototype.setTimeoutInterval = function(ms) {
<a name="line327"></a>  this.timeoutInterval_ = Math.max(0, ms);
<a name="line328"></a>};
<a name="line329"></a>
<a name="line330"></a>
<a name="line331"></a>/**
<a name="line332"></a> * Instance send that actually uses XMLHttpRequest to make a server call.
<a name="line333"></a> * @param {string|goog.Uri} url Uri to make request too.
<a name="line334"></a> * @param {string} opt_method Send method, default: GET.
<a name="line335"></a> * @param {string|GearsBlob} opt_content Post data. This can be a Gears blob
<a name="line336"></a> *     if the underlying HTTP request object is a Gears HTTP request.
<a name="line337"></a> * @param {Object|goog.structs.Map} opt_headers Map of headers to add to the
<a name="line338"></a> *     request.
<a name="line339"></a> */
<a name="line340"></a>goog.net.XhrIo.prototype.send = function(url, opt_method, opt_content,
<a name="line341"></a>                                           opt_headers) {
<a name="line342"></a>  if (this.active_) {
<a name="line343"></a>    throw Error(&#39;[goog.net.XhrIo] Object is active with another request&#39;);
<a name="line344"></a>  }
<a name="line345"></a>
<a name="line346"></a>  var method = opt_method || &#39;GET&#39;;
<a name="line347"></a>
<a name="line348"></a>  this.lastUri_ = url;
<a name="line349"></a>  this.lastError_ = &#39;&#39;;
<a name="line350"></a>  this.lastErrorCode_ = goog.net.ErrorCode.NO_ERROR;
<a name="line351"></a>  this.lastMethod_ = method;
<a name="line352"></a>  this.errorDispatched_ = false;
<a name="line353"></a>  this.active_ = true;
<a name="line354"></a>
<a name="line355"></a>  // Use the factory to create the XHR object and options
<a name="line356"></a>  this.xhr_ = new goog.net.XmlHttp();
<a name="line357"></a>  this.xhrOptions_ = goog.net.XmlHttp.getOptions();
<a name="line358"></a>
<a name="line359"></a>  // We tell the Xhr Monitor that we are opening an XMLHttpRequest.  This stops
<a name="line360"></a>  // IframeIo from destroying iframes that may have been the source of the
<a name="line361"></a>  // execution context, which can result in an error in FF.  See xhrmonitor.js
<a name="line362"></a>  // for more details.
<a name="line363"></a>  goog.net.xhrMonitor.markXhrOpen(this.xhr_);
<a name="line364"></a>
<a name="line365"></a>  // Set up the onreadystatechange callback
<a name="line366"></a>  this.xhr_.onreadystatechange = goog.bind(this.onReadyStateChange_, this);
<a name="line367"></a>
<a name="line368"></a>  /**
<a name="line369"></a>   * Try to open the XMLHttpRequest (always async), if an error occurs here it
<a name="line370"></a>   * is generally permission denied
<a name="line371"></a>   * @preserveTry
<a name="line372"></a>   */
<a name="line373"></a>  try {
<a name="line374"></a>    this.logger_.fine(this.formatMsg_(&#39;Opening Xhr&#39;));
<a name="line375"></a>    this.inOpen_ = true;
<a name="line376"></a>    this.xhr_.open(method, url, true);  // Always async!
<a name="line377"></a>    this.inOpen_ = false;
<a name="line378"></a>  } catch (err) {
<a name="line379"></a>    this.logger_.fine(this.formatMsg_(&#39;Error opening Xhr: &#39; + err.message));
<a name="line380"></a>    this.error_(goog.net.ErrorCode.EXCEPTION, err);
<a name="line381"></a>    return;
<a name="line382"></a>  }
<a name="line383"></a>
<a name="line384"></a>  // We can&#39;t use null since this won&#39;t allow POSTs to have a content length
<a name="line385"></a>  // specified which will cause some proxies to return a 411 error.
<a name="line386"></a>  var content = opt_content || &#39;&#39;;
<a name="line387"></a>
<a name="line388"></a>  var headers = this.headers.clone();
<a name="line389"></a>
<a name="line390"></a>  // Add headers specific to this request
<a name="line391"></a>  if (opt_headers) {
<a name="line392"></a>    goog.structs.forEach(opt_headers, function(value, key) {
<a name="line393"></a>      headers.set(key, value);
<a name="line394"></a>    });
<a name="line395"></a>  }
<a name="line396"></a>
<a name="line397"></a>  if (method == &#39;POST&#39; &amp;&amp;
<a name="line398"></a>      !headers.containsKey(goog.net.XhrIo.CONTENT_TYPE_HEADER)) {
<a name="line399"></a>    // For POST requests, default to the url-encoded form content type.
<a name="line400"></a>    headers.set(goog.net.XhrIo.CONTENT_TYPE_HEADER,
<a name="line401"></a>                goog.net.XhrIo.FORM_CONTENT_TYPE);
<a name="line402"></a>  }
<a name="line403"></a>
<a name="line404"></a>  // Add the headers to the Xhr object
<a name="line405"></a>  goog.structs.forEach(headers, function(value, key) {
<a name="line406"></a>    this.xhr_.setRequestHeader(key, value);
<a name="line407"></a>  }, this);
<a name="line408"></a>
<a name="line409"></a>  /**
<a name="line410"></a>   * Try to send the request, or other wise report an error (404 not found).
<a name="line411"></a>   * @preserveTry
<a name="line412"></a>   */
<a name="line413"></a>  try {
<a name="line414"></a>    if (this.timeoutId_) {
<a name="line415"></a>      // This should never happen, since the if (this.active_) above shouldn&#39;t
<a name="line416"></a>      // let execution reach this point if there is a request in progress...
<a name="line417"></a>      goog.Timer.defaultTimerObject.clearTimeout(this.timeoutId_);
<a name="line418"></a>      this.timeoutId_ = null;
<a name="line419"></a>    }
<a name="line420"></a>    if (this.timeoutInterval_ &gt; 0) {
<a name="line421"></a>      this.logger_.fine(this.formatMsg_(&#39;Will abort after &#39; +
<a name="line422"></a>          this.timeoutInterval_ + &#39;ms if incomplete&#39;));
<a name="line423"></a>      this.timeoutId_ = goog.Timer.defaultTimerObject.setTimeout(
<a name="line424"></a>          goog.bind(this.timeout_, this), this.timeoutInterval_);
<a name="line425"></a>    }
<a name="line426"></a>    this.logger_.fine(this.formatMsg_(&#39;Sending request&#39;));
<a name="line427"></a>    this.inSend_ = true;
<a name="line428"></a>    this.xhr_.send(content);
<a name="line429"></a>    this.inSend_ = false;
<a name="line430"></a>
<a name="line431"></a>  } catch (err) {
<a name="line432"></a>    this.logger_.fine(this.formatMsg_(&#39;Send error: &#39; + err.message));
<a name="line433"></a>    this.error_(goog.net.ErrorCode.EXCEPTION, err);
<a name="line434"></a>  }
<a name="line435"></a>};
<a name="line436"></a>
<a name="line437"></a>
<a name="line438"></a>/**
<a name="line439"></a> * Override of dispatchEvent.  We need to keep track if an XMLHttpRequest is
<a name="line440"></a> * being sent from the context of another requests&#39; repsonse.  If it is then, we
<a name="line441"></a> * make the XHR send async.
<a name="line442"></a> * @param {goog.events.Event|string} e Event to dispatch.
<a name="line443"></a> * @return {boolean} Whether the dispatch completed without a handler calling
<a name="line444"></a> *     preventDefault.
<a name="line445"></a> */
<a name="line446"></a>goog.net.XhrIo.prototype.dispatchEvent = function(e) {
<a name="line447"></a>  if (this.xhr_) {
<a name="line448"></a>    goog.net.xhrMonitor.pushContext(this.xhr_);
<a name="line449"></a>    try {
<a name="line450"></a>      return goog.net.XhrIo.superClass_.dispatchEvent.call(this, e);
<a name="line451"></a>    } finally {
<a name="line452"></a>      goog.net.xhrMonitor.popContext();
<a name="line453"></a>    }
<a name="line454"></a>  } else {
<a name="line455"></a>    return goog.net.XhrIo.superClass_.dispatchEvent.call(this, e);
<a name="line456"></a>  }
<a name="line457"></a>};
<a name="line458"></a>
<a name="line459"></a>
<a name="line460"></a>/**
<a name="line461"></a> * The request didn&#39;t complete after {@link goog.net.XhrIo#timeoutInterval_}
<a name="line462"></a> * milliseconds; raises a {@link goog.net.EventType.TIMEOUT} event and aborts
<a name="line463"></a> * the request.
<a name="line464"></a> * @private
<a name="line465"></a> */
<a name="line466"></a>goog.net.XhrIo.prototype.timeout_ = function() {
<a name="line467"></a>  if (typeof goog == &#39;undefined&#39;) {
<a name="line468"></a>    // If goog is undefined then the callback has occurred as the application
<a name="line469"></a>    // is unloading and will error.  Thus we let it silently fail.
<a name="line470"></a>  } else if (this.xhr_) {
<a name="line471"></a>    this.lastError_ = &#39;Timed out after &#39; + this.timeoutInterval_ +
<a name="line472"></a>                      &#39;ms, aborting&#39;;
<a name="line473"></a>    this.lastErrorCode_ = goog.net.ErrorCode.TIMEOUT;
<a name="line474"></a>    this.logger_.fine(this.formatMsg_(this.lastError_));
<a name="line475"></a>    this.dispatchEvent(goog.net.EventType.TIMEOUT);
<a name="line476"></a>    this.abort(goog.net.ErrorCode.TIMEOUT);
<a name="line477"></a>  }
<a name="line478"></a>};
<a name="line479"></a>
<a name="line480"></a>
<a name="line481"></a>/**
<a name="line482"></a> * Something errorred, so inactivate, fire error callback and clean up
<a name="line483"></a> * @param {goog.net.ErrorCode} errorCode The error code.
<a name="line484"></a> * @param {Error} err The error object.
<a name="line485"></a> * @private
<a name="line486"></a> */
<a name="line487"></a>goog.net.XhrIo.prototype.error_ = function(errorCode, err) {
<a name="line488"></a>  this.active_ = false;
<a name="line489"></a>  if (this.xhr_) {
<a name="line490"></a>    this.inAbort_ = true;
<a name="line491"></a>    this.xhr_.abort();  // Ensures XHR isn&#39;t hung (FF)
<a name="line492"></a>    this.inAbort_ = false;
<a name="line493"></a>  }
<a name="line494"></a>  this.lastError_ = err;
<a name="line495"></a>  this.lastErrorCode_ = errorCode;
<a name="line496"></a>  this.dispatchErrors_();
<a name="line497"></a>  this.cleanUpXhr_()
<a name="line498"></a>};
<a name="line499"></a>
<a name="line500"></a>
<a name="line501"></a>/**
<a name="line502"></a> * Dispatches COMPLETE and ERROR in case of an error. This ensures that we do
<a name="line503"></a> * not dispatch multiple error events.
<a name="line504"></a> * @private
<a name="line505"></a> */
<a name="line506"></a>goog.net.XhrIo.prototype.dispatchErrors_ = function() {
<a name="line507"></a>  if (!this.errorDispatched_) {
<a name="line508"></a>    this.errorDispatched_ = true;
<a name="line509"></a>    this.dispatchEvent(goog.net.EventType.COMPLETE);
<a name="line510"></a>    this.dispatchEvent(goog.net.EventType.ERROR);
<a name="line511"></a>  }
<a name="line512"></a>};
<a name="line513"></a>
<a name="line514"></a>
<a name="line515"></a>/**
<a name="line516"></a> * Abort the current XMLHttpRequest
<a name="line517"></a> * @param {goog.net.ErrorCode} opt_failureCode Optional error code to use -
<a name="line518"></a> *     defaults to ABORT.
<a name="line519"></a> */
<a name="line520"></a>goog.net.XhrIo.prototype.abort = function(opt_failureCode) {
<a name="line521"></a>  if (this.xhr_) {
<a name="line522"></a>    this.logger_.fine(this.formatMsg_(&#39;Aborting&#39;));
<a name="line523"></a>    this.active_ = false;
<a name="line524"></a>    this.inAbort_ = true;
<a name="line525"></a>    this.xhr_.abort();
<a name="line526"></a>    this.inAbort_ = false;
<a name="line527"></a>    this.lastErrorCode_ = opt_failureCode || goog.net.ErrorCode.ABORT;
<a name="line528"></a>    this.dispatchEvent(goog.net.EventType.COMPLETE);
<a name="line529"></a>    this.dispatchEvent(goog.net.EventType.ABORT);
<a name="line530"></a>    this.cleanUpXhr_();
<a name="line531"></a>  }
<a name="line532"></a>};
<a name="line533"></a>
<a name="line534"></a>
<a name="line535"></a>/**
<a name="line536"></a> * Nullifies all callbacks to reduce risks of leaks.
<a name="line537"></a> */
<a name="line538"></a>goog.net.XhrIo.prototype.disposeInternal = function() {
<a name="line539"></a>  if (this.xhr_) {
<a name="line540"></a>    // We explicitly do not call xhr_.abort() unless active_ is still true.
<a name="line541"></a>    // This is to avoid unnecessarily aborting a successful request when
<a name="line542"></a>    // disposeInternal() is called in a callback triggered by a complete
<a name="line543"></a>    // response, but in which browser cleanup has not yet finished.
<a name="line544"></a>    // (See http://b/issue?id=1684217.)
<a name="line545"></a>    if (this.active_) {
<a name="line546"></a>      this.active_ = false;
<a name="line547"></a>      this.inAbort_ = true;
<a name="line548"></a>      this.xhr_.abort();
<a name="line549"></a>      this.inAbort_ = false;
<a name="line550"></a>    }
<a name="line551"></a>    this.cleanUpXhr_(true);
<a name="line552"></a>  }
<a name="line553"></a>
<a name="line554"></a>  goog.net.XhrIo.superClass_.disposeInternal.call(this);
<a name="line555"></a>};
<a name="line556"></a>
<a name="line557"></a>
<a name="line558"></a>/**
<a name="line559"></a> * Internal handler for the XHR object&#39;s readystatechange event.  This method
<a name="line560"></a> * checks the status and the readystate and fires the correct callbacks.
<a name="line561"></a> * If the request has ended, the handlers are cleaned up and the XHR object is
<a name="line562"></a> * nullified.
<a name="line563"></a> * @private
<a name="line564"></a> */
<a name="line565"></a>goog.net.XhrIo.prototype.onReadyStateChange_ = function() {
<a name="line566"></a>  if (!this.inOpen_ &amp;&amp; !this.inSend_ &amp;&amp; !this.inAbort_) {
<a name="line567"></a>    // Were not being called from within a call to this.xhr_.send
<a name="line568"></a>    // this.xhr_.abort, or this.xhr_.open, so this is an entry point
<a name="line569"></a>    this.onReadyStateChangeEntryPoint_();
<a name="line570"></a>  } else {
<a name="line571"></a>    this.onReadyStateChangeHelper_();
<a name="line572"></a>  }
<a name="line573"></a>};
<a name="line574"></a>
<a name="line575"></a>
<a name="line576"></a>/**
<a name="line577"></a> * Used to protect the onreadystatechange handler entry point.  Necessary
<a name="line578"></a> * as {#onReadyStateChange_} maybe called from within send or abort, this
<a name="line579"></a> * method is only called when {#onReadyStateChange_} is called as an
<a name="line580"></a> * entry point.
<a name="line581"></a> * {@see #protectEntryPoints}
<a name="line582"></a> * @private
<a name="line583"></a> */
<a name="line584"></a>goog.net.XhrIo.prototype.onReadyStateChangeEntryPoint_ = function() {
<a name="line585"></a>  this.onReadyStateChangeHelper_();
<a name="line586"></a>};
<a name="line587"></a>
<a name="line588"></a>
<a name="line589"></a>/**
<a name="line590"></a> * Helper for {@link #onReadyStateChange_}.  This is used so that
<a name="line591"></a> * entry point calls to {@link #onReadyStateChange_} can be routed through
<a name="line592"></a> * {@link #onReadyStateChangeEntryPoint_}.
<a name="line593"></a> * @private
<a name="line594"></a> */
<a name="line595"></a>goog.net.XhrIo.prototype.onReadyStateChangeHelper_ = function() {
<a name="line596"></a>  if (!this.active_) {
<a name="line597"></a>    // can get called inside abort call
<a name="line598"></a>    return;
<a name="line599"></a>  }
<a name="line600"></a>
<a name="line601"></a>  if (typeof goog == &#39;undefined&#39;) {
<a name="line602"></a>    // NOTE: If goog is undefined then the callback has occurred as the
<a name="line603"></a>    // application is unloading and will error.  Thus we let it silently fail.
<a name="line604"></a>
<a name="line605"></a>  } else if (
<a name="line606"></a>      this.xhrOptions_[goog.net.XmlHttp.OptionType.LOCAL_REQUEST_ERROR] &amp;&amp;
<a name="line607"></a>      this.getReadyState() == goog.net.XmlHttp.ReadyState.COMPLETE &amp;&amp;
<a name="line608"></a>      this.getStatus() == 2) {
<a name="line609"></a>    // NOTE: In IE if send() errors on a *local* request the readystate
<a name="line610"></a>    // is still changed to COMPLETE.  We need to ignore it and allow the
<a name="line611"></a>    // try/catch around send() to pick up the error.
<a name="line612"></a>    this.logger_.fine(this.formatMsg_(
<a name="line613"></a>        &#39;Local request error detected and ignored&#39;));
<a name="line614"></a>
<a name="line615"></a>  } else {
<a name="line616"></a>
<a name="line617"></a>    // In IE when the response has been cached we sometimes get the callback
<a name="line618"></a>    // from inside the send call and this usually breaks code that assumes that
<a name="line619"></a>    // XhrIo is asynchronous.  If that is the case we delay the callback
<a name="line620"></a>    // using a timer.
<a name="line621"></a>    if (this.inSend_ &amp;&amp;
<a name="line622"></a>        this.getReadyState() == goog.net.XmlHttp.ReadyState.COMPLETE) {
<a name="line623"></a>      goog.Timer.defaultTimerObject.setTimeout(
<a name="line624"></a>          goog.bind(this.onReadyStateChange_, this), 0);
<a name="line625"></a>      return;
<a name="line626"></a>    }
<a name="line627"></a>
<a name="line628"></a>    this.dispatchEvent(goog.net.EventType.READY_STATE_CHANGE);
<a name="line629"></a>
<a name="line630"></a>    // readyState indicates the transfer has finished
<a name="line631"></a>    if (this.isComplete()) {
<a name="line632"></a>      this.logger_.fine(this.formatMsg_(&#39;Request complete&#39;));
<a name="line633"></a>
<a name="line634"></a>      this.active_ = false;
<a name="line635"></a>
<a name="line636"></a>      // Call the specific callbacks for success or failure. Only call the
<a name="line637"></a>      // success if the status is 200 (HTTP_OK) or 304 (HTTP_CACHED)
<a name="line638"></a>      if (this.isSuccess()) {
<a name="line639"></a>        this.dispatchEvent(goog.net.EventType.COMPLETE);
<a name="line640"></a>        this.dispatchEvent(goog.net.EventType.SUCCESS);
<a name="line641"></a>      } else {
<a name="line642"></a>        this.lastErrorCode_ = goog.net.ErrorCode.HTTP_ERROR;
<a name="line643"></a>        this.lastError_ = this.getStatusText() + &#39; [&#39; + this.getStatus() + &#39;]&#39;;
<a name="line644"></a>        this.dispatchErrors_();
<a name="line645"></a>      }
<a name="line646"></a>
<a name="line647"></a>      this.cleanUpXhr_();
<a name="line648"></a>    }
<a name="line649"></a>  }
<a name="line650"></a>};
<a name="line651"></a>
<a name="line652"></a>
<a name="line653"></a>/**
<a name="line654"></a> * Remove the listener to protect against leaks, and nullify the XMLHttpRequest
<a name="line655"></a> * object.
<a name="line656"></a> * @param {boolean} opt_fromDispose If this is from the dispose (don&#39;t want to
<a name="line657"></a> *     fire any events).
<a name="line658"></a> * @private
<a name="line659"></a> */
<a name="line660"></a>goog.net.XhrIo.prototype.cleanUpXhr_ = function(opt_fromDispose) {
<a name="line661"></a>  if (this.xhr_) {
<a name="line662"></a>    // Save reference so we can mark it as closed after the READY event.  The
<a name="line663"></a>    // READY event may trigger another request, thus we must nullify this.xhr_
<a name="line664"></a>    var xhr = this.xhr_;
<a name="line665"></a>    var clearedOnReadyStateChange =
<a name="line666"></a>        this.xhrOptions_[goog.net.XmlHttp.OptionType.USE_NULL_FUNCTION] ?
<a name="line667"></a>              goog.nullFunction : null;
<a name="line668"></a>    this.xhr_ = null;
<a name="line669"></a>    this.xhrOptions_ = null;
<a name="line670"></a>
<a name="line671"></a>    if (this.timeoutId_) {
<a name="line672"></a>      // Cancel any pending timeout event handler.
<a name="line673"></a>      goog.Timer.defaultTimerObject.clearTimeout(this.timeoutId_);
<a name="line674"></a>      this.timeoutId_ = null;
<a name="line675"></a>    }
<a name="line676"></a>
<a name="line677"></a>    if (!opt_fromDispose) {
<a name="line678"></a>      goog.net.xhrMonitor.pushContext(xhr);
<a name="line679"></a>      this.dispatchEvent(goog.net.EventType.READY);
<a name="line680"></a>      goog.net.xhrMonitor.popContext();
<a name="line681"></a>    }
<a name="line682"></a>
<a name="line683"></a>    // Mark the request as having completed.
<a name="line684"></a>    goog.net.xhrMonitor.markXhrClosed(xhr);
<a name="line685"></a>
<a name="line686"></a>    try {
<a name="line687"></a>      // NOTE: Not nullifying in FireFox can still leak if the callbacks
<a name="line688"></a>      // are defined in the same scope as the instance of XhrIo. But, IE doesn&#39;t
<a name="line689"></a>      // allow you to set the onreadystatechange to NULL so nullFunction is
<a name="line690"></a>      // used.
<a name="line691"></a>      xhr.onreadystatechange = clearedOnReadyStateChange;
<a name="line692"></a>    } catch (e) {
<a name="line693"></a>      // This seems to occur with a Gears HTTP request. Delayed the setting of
<a name="line694"></a>      // this onreadystatechange until after READY is sent out and catching the
<a name="line695"></a>      // error to see if we can track down the problem.
<a name="line696"></a>      this.logger_.severe(&#39;Problem encountered resetting onreadystatechange: &#39; +
<a name="line697"></a>                          e.message);
<a name="line698"></a>    }
<a name="line699"></a>  }
<a name="line700"></a>};
<a name="line701"></a>
<a name="line702"></a>
<a name="line703"></a>/**
<a name="line704"></a> * @return {boolean} Whether there is an active request.
<a name="line705"></a> */
<a name="line706"></a>goog.net.XhrIo.prototype.isActive = function() {
<a name="line707"></a>  return this.active_;
<a name="line708"></a>};
<a name="line709"></a>
<a name="line710"></a>
<a name="line711"></a>/**
<a name="line712"></a> * @return {boolean} Whether the request has completed.
<a name="line713"></a> */
<a name="line714"></a>goog.net.XhrIo.prototype.isComplete = function() {
<a name="line715"></a>  return this.getReadyState() == goog.net.XmlHttp.ReadyState.COMPLETE;
<a name="line716"></a>};
<a name="line717"></a>
<a name="line718"></a>
<a name="line719"></a>/**
<a name="line720"></a> * @return {boolean} Whether the request completed with a success.
<a name="line721"></a> */
<a name="line722"></a>goog.net.XhrIo.prototype.isSuccess = function() {
<a name="line723"></a>  switch (this.getStatus()) {
<a name="line724"></a>    case 0:         // Used for local XHR requests
<a name="line725"></a>    case 200:       // Http Success
<a name="line726"></a>    case 204:       // Http Success - no content
<a name="line727"></a>    case 304:       // Http Cache
<a name="line728"></a>      return true;
<a name="line729"></a>
<a name="line730"></a>    default:
<a name="line731"></a>      return false;
<a name="line732"></a>  }
<a name="line733"></a>};
<a name="line734"></a>
<a name="line735"></a>
<a name="line736"></a>/**
<a name="line737"></a> * Get the readystate from the Xhr object
<a name="line738"></a> * Will only return correct result when called from the context of a callback
<a name="line739"></a> * @return {goog.net.XmlHttp.ReadyState} goog.net.XmlHttp.ReadyState.*.
<a name="line740"></a> */
<a name="line741"></a>goog.net.XhrIo.prototype.getReadyState = function() {
<a name="line742"></a>  return this.xhr_ ?
<a name="line743"></a>      /** @type {goog.net.XmlHttp.ReadyState} */ (this.xhr_.readyState) :
<a name="line744"></a>      goog.net.XmlHttp.ReadyState.UNINITIALIZED;
<a name="line745"></a>};
<a name="line746"></a>
<a name="line747"></a>
<a name="line748"></a>/**
<a name="line749"></a> * Get the status from the Xhr object
<a name="line750"></a> * Will only return correct result when called from the context of a callback
<a name="line751"></a> * @return {number} Http status.
<a name="line752"></a> */
<a name="line753"></a>goog.net.XhrIo.prototype.getStatus = function() {
<a name="line754"></a>  /**
<a name="line755"></a>   * IE doesn&#39;t like you checking status until the readystate is greater than 2
<a name="line756"></a>   * (i.e. it is recieving or complete).  The try/catch is used for when the
<a name="line757"></a>   * page is unloading and an ERROR_NOT_AVAILABLE may occur when accessing xhr_.
<a name="line758"></a>   * @preserveTry
<a name="line759"></a>   */
<a name="line760"></a>  try {
<a name="line761"></a>    return this.getReadyState() &gt; goog.net.XmlHttp.ReadyState.LOADED ?
<a name="line762"></a>        this.xhr_.status : -1;
<a name="line763"></a>  } catch (e) {
<a name="line764"></a>    this.logger_.warning(&#39;Can not get status: &#39; + e.message);
<a name="line765"></a>    return -1;
<a name="line766"></a>  }
<a name="line767"></a>};
<a name="line768"></a>
<a name="line769"></a>
<a name="line770"></a>/**
<a name="line771"></a> * Get the status text from the Xhr object
<a name="line772"></a> * Will only return correct result when called from the context of a callback
<a name="line773"></a> * @return {string} Status text.
<a name="line774"></a> */
<a name="line775"></a>goog.net.XhrIo.prototype.getStatusText = function() {
<a name="line776"></a>  /**
<a name="line777"></a>   * IE doesn&#39;t like you checking status until the readystate is greater than 2
<a name="line778"></a>   * (i.e. it is recieving or complete).  The try/catch is used for when the
<a name="line779"></a>   * page is unloading and an ERROR_NOT_AVAILABLE may occur when accessing xhr_.
<a name="line780"></a>   * @preserveTry
<a name="line781"></a>   */
<a name="line782"></a>  try {
<a name="line783"></a>    return this.getReadyState() &gt; goog.net.XmlHttp.ReadyState.LOADED ?
<a name="line784"></a>        this.xhr_.statusText : &#39;&#39;;
<a name="line785"></a>  } catch (e) {
<a name="line786"></a>    this.logger_.fine(&#39;Can not get status: &#39; + e.message);
<a name="line787"></a>    return &#39;&#39;;
<a name="line788"></a>  }
<a name="line789"></a>};
<a name="line790"></a>
<a name="line791"></a>
<a name="line792"></a>/**
<a name="line793"></a> * Get the last Uri that was requested
<a name="line794"></a> * @return {string} Last Uri.
<a name="line795"></a> */
<a name="line796"></a>goog.net.XhrIo.prototype.getLastUri = function() {
<a name="line797"></a>  return String(this.lastUri_);
<a name="line798"></a>};
<a name="line799"></a>
<a name="line800"></a>
<a name="line801"></a>/**
<a name="line802"></a> * Get the response text from the Xhr object
<a name="line803"></a> * Will only return correct result when called from the context of a callback
<a name="line804"></a> * @return {string} Result from the server.
<a name="line805"></a> */
<a name="line806"></a>goog.net.XhrIo.prototype.getResponseText = function() {
<a name="line807"></a>  return this.xhr_ ? this.xhr_.responseText : &#39;&#39;;
<a name="line808"></a>};
<a name="line809"></a>
<a name="line810"></a>
<a name="line811"></a>/**
<a name="line812"></a> * Get the response XML from the Xhr object
<a name="line813"></a> * Will only return correct result when called from the context of a callback
<a name="line814"></a> * @return {Document?} The DOM Document representing the XML file.
<a name="line815"></a> */
<a name="line816"></a>goog.net.XhrIo.prototype.getResponseXml = function() {
<a name="line817"></a>  return this.xhr_ ? this.xhr_.responseXML : null;
<a name="line818"></a>};
<a name="line819"></a>
<a name="line820"></a>
<a name="line821"></a>/**
<a name="line822"></a> * Get the response and evaluates it as JSON from the Xhr object
<a name="line823"></a> * Will only return correct result when called from the context of a callback
<a name="line824"></a> * @return {Object|undefined} JavaScript object.
<a name="line825"></a> */
<a name="line826"></a>goog.net.XhrIo.prototype.getResponseJson = function() {
<a name="line827"></a>  return this.xhr_ ? goog.json.parse(this.xhr_.responseText) : undefined;
<a name="line828"></a>};
<a name="line829"></a>
<a name="line830"></a>
<a name="line831"></a>/**
<a name="line832"></a> * Get the value of the response-header with the given name from the Xhr object
<a name="line833"></a> * Will only return correct result when called from the context of a callback
<a name="line834"></a> * and the request has completed
<a name="line835"></a> * @param {string} key The name of the response-header to retrieve.
<a name="line836"></a> * @return {string|undefined} The value of the response-header named key.
<a name="line837"></a> */
<a name="line838"></a>goog.net.XhrIo.prototype.getResponseHeader = function(key) {
<a name="line839"></a>  return this.xhr_ &amp;&amp; this.isComplete() ?
<a name="line840"></a>      this.xhr_.getResponseHeader(key) : undefined;
<a name="line841"></a>};
<a name="line842"></a>
<a name="line843"></a>
<a name="line844"></a>/**
<a name="line845"></a> * Get the last error message
<a name="line846"></a> * @return {goog.net.ErrorCode} Last error code.
<a name="line847"></a> */
<a name="line848"></a>goog.net.XhrIo.prototype.getLastErrorCode = function() {
<a name="line849"></a>  return this.lastErrorCode_;
<a name="line850"></a>};
<a name="line851"></a>
<a name="line852"></a>
<a name="line853"></a>/**
<a name="line854"></a> * Get the last error message
<a name="line855"></a> * @return {string} Last error message.
<a name="line856"></a> */
<a name="line857"></a>goog.net.XhrIo.prototype.getLastError = function() {
<a name="line858"></a>  return goog.isString(this.lastError_) ? this.lastError_ :
<a name="line859"></a>    String(this.lastError_);
<a name="line860"></a>};
<a name="line861"></a>
<a name="line862"></a>
<a name="line863"></a>/**
<a name="line864"></a> * Adds the last method, status and URI to the message.  This is used to add
<a name="line865"></a> * this information to the logging calls.
<a name="line866"></a> * @param {string} msg The message text that we want to add the extra text to.
<a name="line867"></a> * @return {string} The message with the extra text appended.
<a name="line868"></a> * @private
<a name="line869"></a> */
<a name="line870"></a>goog.net.XhrIo.prototype.formatMsg_ = function(msg) {
<a name="line871"></a>  return msg + &#39; [&#39; + this.lastMethod_ + &#39; &#39; + this.lastUri_ + &#39; &#39; +
<a name="line872"></a>      this.getStatus() + &#39;]&#39;;
<a name="line873"></a>};
</pre>


</body>
</html>
